<?php
/**
 * @author Feng
 * @date 2012-6-16
 */
class collection_rule_row extends system_concept_row {
	
	public function getLinkId() {
		return system_encrypt::alphaId($this->get('key'));
	}

	protected $_cover = null;
	/**
	 * @return resource_display
	 */
	public function getCover() {
		if($this->_cover === null || ($this->_cover->getHash() && $this->_cover->getHash() != $this->get('cover'))) {
			$this->_cover = new resource_display($this->get('cover'));
		}
		return $this->_cover;
	}
	
	/**
	 * @return collection_collect_ruleRow
	 */
	public function setType($type) {
		$type = new collection_rule_type($type);
		$this->set('type', $type->getId());
		return $this;
	}

	/**
	 * @return collection_collect_ruleRow
	 */
	public function setRule($rule) {
		if(is_array($rule)) {
			$rule = serialize($rule);
		}
		$this->set('rule', $rule);
		return $this;
	}	
	/**
	 * @return collection_collect_abstract
	 */
	public function getRule() {
		$type = new collection_rule_type($this->get('type'));
		$class = 'collection_collect_' . strtolower($type->getKey());
		return new $class($this);
	}
	/**
	 * @return collection_collect_abstract
	 */
	public function setParams($params) {
		if(is_array($params)) {
			$params = serialize($params);
		}
		$this->set('params', $params);
		return $this;
	}
	/**
	 * @return collection_collect_params
	 */
	public function getParams() {
		return new collection_collect_params($this->get('params'));
	}
	
}
